package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Main4 {
	public static void main(String[] args) {
		List<StuUser> stuList = new ArrayList<StuUser>();
		stuList.add(new StuUser(15, "6"));
		stuList.add(new StuUser(20, "4"));	
		stuList.add(new StuUser(10, "1"));

		User user = max1(stuList,new StuUserComparator());
		Object user0 = max1(stuList,new UserReverseComparator());
		//String max = max(stuList);
		System.out.println(user);
		System.out.println(user0);
    }
	public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> list) {
		return Collections.max(list);
	}
	
	public static <T> T max1(Collection<? extends T> list,Comparator<? super T> com) {
		return Collections.max(list, com);
	}
}	

class User implements Comparable<User> {
	private int age;
	public User(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	@Override
	public int compareTo(User o) {
		return age - o.age;
	}

	@Override
	public String toString() {
		return "User [age=" + age + "]";
	}

}

class StuUser extends User {
	private String no;
	public StuUser(int age, String no) {
		super(age);
		this.no = no;
	}

	public String getNo() {
		return no;
	}

	@Override
	public String toString() {
		return "StuUser [no=" + no + ", toString()=" + super.toString() + "]";
	}

}

class UserReverseComparator implements Comparator<User> {
	@Override
	public int compare(User o1, User o2) {
		return o2.getAge() - o1.getAge();
	}

}

class StuUserComparator implements Comparator<StuUser> {
	@Override
	public int compare(StuUser o1, StuUser o2) {
		return o1.getNo().compareTo(o2.getNo());
	}

}




